<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: onvif-nvt.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: onvif-nvt.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>const Util = require('./utils/util')

/**
 * If the OnvifManager class is used to connect to a camera, it will
 * manage your devices (cameras). It stores cameras by address. You
 * can use address to retrieve the camera.
 */
class OnvifManager {
  constructor () {
    this.discovery = null
    this.cameras = {}
  }

  /**
   * Add a module to OnvifManager. Currently, the only available module is 'discovery'.
   * @param {string} name The name of the module.
   */
  add (name) {
    switch (name) {
      case 'discovery':
        let Discovery = require('./modules/discovery')
        this.discovery = new Discovery()
        break
      default:
        throw new Error(`The only acceptable module that can be added to OnvifManager is "discovery" - not "${name}".`)
    }
  }

  /**
   * Connects to an ONVIF device.
   * @param {string} address The address of the ONVIF device (ie: 10.10.1.20)
   * @param {integer=} port The port of the ONVIF device. Defaults to 80.
   * @param {string=} username The user name used to make a connection.
   * @param {string=} password The password used to make a connection.
   * @param {string=} servicePath The service path for the camera. If null or 'undefined' the default path according to the ONVIF spec will be used.
   * @param {callback=} callback Optional callback, instead of a Promise.
   * @returns A Promise. On success, resolve contains a Camera object.
   */
  connect (address, port, username, password, servicePath, callback) {
    let promise = new Promise((resolve, reject) => {
      let errMsg = ''
      if ((errMsg = Util.isInvalidValue(address, 'string'))) {
        reject(new Error(`The "address" argument for connect is invalid: ` + errMsg))
        return
      }

      let c = this.cameras[address]
      if (c) {
        resolve(c)
        return
      }

      // default to port 80 if none provided
      port = port || 80

      let Camera = require('./camera')
      let camera = new Camera()
      this.cameras[address] = camera

      return camera.connect(address, port, username, password, servicePath)
        .then(results => {
          // console.log(results)
          resolve(camera)
        })
        .catch(error => {
          console.error(error)
          reject(error)
        })
    })
    if (Util.isValidCallback(callback)) {
      promise.then(results => {
        callback(null, results)
      }).catch(error => {
        callback(error)
      })
    }
    else {
      return promise
    }
  }
}

module.exports = new OnvifManager()
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.html">Access</a></li><li><a href="AccessRules.html">AccessRules</a></li><li><a href="Action.html">Action</a></li><li><a href="Analytics.html">Analytics</a></li><li><a href="Camera.html">Camera</a></li><li><a href="Core.html">Core</a></li><li><a href="Credential.html">Credential</a></li><li><a href="DeviceIO.html">DeviceIO</a></li><li><a href="Discovery.html">Discovery</a></li><li><a href="Display.html">Display</a></li><li><a href="Door.html">Door</a></li><li><a href="Events.html">Events</a></li><li><a href="Imaging.html">Imaging</a></li><li><a href="Media.html">Media</a></li><li><a href="Media2.html">Media2</a></li><li><a href="OnvifManager.html">OnvifManager</a></li><li><a href="Ptz.html">Ptz</a></li><li><a href="Receiver.html">Receiver</a></li><li><a href="Recording.html">Recording</a></li><li><a href="Replay.html">Replay</a></li><li><a href="Schedule.html">Schedule</a></li><li><a href="Search.html">Search</a></li><li><a href="Security.html">Security</a></li><li><a href="Snapshot.html">Snapshot</a></li><li><a href="Soap.html">Soap</a></li><li><a href="Thermal.html">Thermal</a></li><li><a href="VideoAnalytics.html">VideoAnalytics</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 14:01:19 GMT-0700 (MST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
